//
//  STEmoticonPageView.swift
//  STVVeibo
//
//  Created by leergou on 16/7/29.
//  Copyright © 2016年 WhiteHouse. All rights reserved.
//

import UIKit
private let STEmoticonPageViewCellID = "STEmoticonPageViewCellID"

class STEmoticonPageView: UICollectionView {

    override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
        super.init(frame: frame, collectionViewLayout: UICollectionViewFlowLayout())
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    //MARK: setupUI
    func setupUI(){
//        backgroundColor = RandomColor()
        dataSource = self
        // 获取layout
        let layout = self.collectionViewLayout as! UICollectionViewFlowLayout
        layout.itemSize = CGSize(width: SCREENW, height: 216 - 37)
        layout.minimumInteritemSpacing = 0
        layout.minimumLineSpacing = 0
        layout.scrollDirection = .Horizontal
        // 注册 cell
        registerClass(STEmoticonPageViewCell.self, forCellWithReuseIdentifier: STEmoticonPageViewCellID)
    }
    
}

extension STEmoticonPageView:UICollectionViewDataSource{
    
    func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
        return STEmoticonTools.emoticonSharedTools.allEmoticons.count
    }
    
    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return STEmoticonTools.emoticonSharedTools.allEmoticons[section].count
    }
    
    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier(STEmoticonPageViewCellID, forIndexPath: indexPath) as! STEmoticonPageViewCell
    
        cell.emoticons = STEmoticonTools.emoticonSharedTools.allEmoticons[indexPath.section][indexPath.item]
//        cell.backgroundColor = RandomColor()
//        cell.indexPath = indexPath
        cell.backgroundColor = self.backgroundColor
        
        return cell
    }
    
}

